<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>注册页面</title>
        <style>
            * {
                padding: 0;
                margin: 0;
                box-sizing: border-box;
            }
            body {
                height: 100vh;
                display: flex;
                align-items: center;
                justify-content: center;
                background-color: lightblue;
            }
            .form {
                width: 400px;
                padding: 15px;
                border-radius: 10px;
                background-color: #fff;
            }
            .form input {
                display: block;
                height: 30px;
                width: 100%;
                margin-top: 10px;
                padding-left: 10px;
            }
            .form h2 {
                text-align: center;
            }
            .form-group {
                margin-top: 30px;
            }
            .btn {
                margin-top: 20px;
                height: 30px;
                border-radius: 5px;
                color: #fff;
                text-align: center;
                line-height: 30px;
                background-color: blue;
            }
        </style>
        <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    </head>
    <body>
        <div class="form">
            <h2>注册</h2>
            <div class="form-group">
                <div>用户名:</div>
                <div>
                    <input
                        id="username"
                        type="text"
                        name="username"
                        placeholder="请输入用户名"
                    />
                </div>
            </div>
            <div class="form-group">
                <div>密码:</div>
                <div>
                    <input
                        id="password"
                        type="text"
                        name="password"
                        placeholder="请输入密码"
                    />
                </div>
            </div>
            <div class="btn">注册</div>
        </div>
    </body>
    <script>
        document.querySelector(".btn").onclick = async function () {
            let username = document.querySelector("#username").value;
            let password = document.querySelector("#password").value;
            let res = await axios.post("http://localhost:3000/register", {
                username,
                password,
            });
            if (res.data.code === 200) {
                alert("注册成功");
                location.href = "./login.html";
            }
        };
    </script>
</html>
